<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IList<DecisionMaking.Domain.Candidate>>" %>
<%@ Import Namespace="DecisionMaking.Domain" %>
<%@ Import Namespace="DecisionMaking.WebApp" %>
<%@ Import Namespace="MvcContrib.UI.Grid" %>
<%@ Import Namespace="MvcContrib.UI.MenuBuilder" %>

<asp:Content ContentPlaceHolderID="TitleContent" runat="server">Manage Candidates</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MenuContent" runat="server">
    <% Html.Menu(Navigation.MainMenu(Url, ((DecisionMaking.Domain.Environment)ViewData["environment"]).Id)); %>
</asp:Content>

<asp:Content ContentPlaceHolderID="MainContent" runat="server">
	<script type="text/javascript">
        function update(context) {
            // Load and deserialize the returned JSON data
            var json = context.get_data();
            var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);
 
            // delete the row from the grid
			$('#candidate-' + data.deletedId).fadeOut();
        }		
	</script>

	<p>
		<%= Html.ActionLink("New Candidate", "Add", new {Id = ((DecisionMaking.Domain.Environment)ViewData["environment"]).Id}, null) %>
	</p>
	<%
        if (Model.Count > 0)
        {
            Html.Grid(Model).Columns(column =>
            {
                column.For(c => c.Name);
                column.For(c => c.IndependentVariableValue).Named(((DecisionMaking.Domain.Environment)ViewData["environment"]).IndependentVariableName);
                column.For(c => Html.ActionLink("Edit", "Edit", new { id = c.Id })).DoNotEncode();
                column.For(c => Ajax.ActionLink("Remove", "Delete", new { id = c.Id }, new AjaxOptions { OnSuccess = "update" })).DoNotEncode();                    
            })
            .RowAttributes(row => new Dictionary<string, object> { { "id", "candidate-" + row.Item.Id } })
            .Render();
        }
	%>
    <p>
        <%= Html.ActionLink("Next", "List", "Agents", new { Id = ((DecisionMaking.Domain.Environment)ViewData["environment"]).Id }, null)%>
    </p>
	      	
</asp:Content>

